define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		function get_data_addressList(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"logisticscomp": [' +
					'{"id": "001","comp_logo": "./img/logistics/logo-shunf.png","comp_name": "顺丰快递","choosen_flg": true},' +
					'{"id": "002","comp_logo": "./img/logistics/logo-yuant.png","comp_name": "园通快递","choosen_flg": true},' +
					'{"id": "003","comp_logo": "./img/logistics/logo-debang.png","comp_name": "德邦快递","choosen_flg": true},' +
					'{"id": "004","comp_logo": "./img/logistics/logo-ems.png","comp_name": "EMS","choosen_flg": true},' +
					'{"id": "005","comp_logo": "./img/logistics/logo-huayu.png","comp_name": "天地华宇","choosen_flg": true},' +
					'{"id": "006","comp_logo": "./img/logistics/logo-ups.png","comp_name": "UPS","choosen_flg": false},' +
					'{"id": "007","comp_logo": "./img/logistics/logo-yunda.png","comp_name": "韵达快递","choosen_flg": false},' +
					'{"id": "008","comp_logo": "./img/logistics/logo-zhongt.png","comp_name": "中通快递","choosen_flg": false}]},' +
					'"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		};
		function get_data_choose(result){
			if(false) {
				result = '{"success": true,"msg": "","result": {"addr_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else{
					return result;
			}
		}
		
		//返回信息
		return {
			//物流公司列表
			address_list: function(nPage, callback,calldone) {
				//post请求
				Http.post({
					method: 'member.logisticscomp.getlist',
					pagelimit: 10,
					nPage: nPage
				}, function(result) {
					//函数回调
					if(callback)
						callback(get_data_addressList(result).result);

				}, function(e) {

				}, function() {
					if(calldone)
					calldone();
					
				});
			},
			submit_data: function(comp, callback) {
				var updateParams = new Object();
				updateParams.comp = comp;
				updateParams = JSON.stringify(updateParams);
				Http.post({
					method: 'member.logisticscomp.choose',
					updateParams: updateParams
				}, function(result) {
						if(callback)
						callback(get_data_choose(result));
				}, function(e) {

				}, function() {

				})
			}

		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Logistics", factory);
});